package stringdemo;

import java.util.Scanner;

public class StringDemo4StringCount {
    public static void main(String[] args) {
        //1.键盘录入一个字符串
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个字符串:");
        String str = sc.next();

        //2.统计 --- 计数器思想
        //定义三个计数器
        int bigCount = 0;
        int smallCount = 0;
        int numberCount = 0;

        //3.遍历字符串
        for (int i = 0; i < str.length(); i++) {
            char s = str.charAt(i);
            //char类型的变量在参与计算的时候自动类型提升为int，查询ascii码表
            if (s>='a' && s<='z'){
                smallCount++;
            } else if (s>='A' && s<='Z') {
                bigCount++;
            } else if (s>='0' && s<='9') {
                numberCount++;
            }
        }

        //4.输出打印
        System.out.println("大写字母有:"+bigCount+"个");
        System.out.println("小写字母有:"+smallCount+"个");
        System.out.println("数字有:"+numberCount+"个");
    }


}
